/*
 *  Copyright 2011 Quytelda K. Gaiwin
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.tamalin.nighthawk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

/**
 * The FilenameActivity class allows the selection of files by filename.
 * @author Quytelda K. Gaiwin
 */
public class FilenameActivity extends Activity
{
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.filename);
		
		Button select = (Button) findViewById(R.id.select);
		mode = getIntent().getExtras().getInt("mode");
		
		//determine if data was passed
		if(getIntent().getExtras().containsKey("data"))
		{
			data = getIntent().getExtras().getString("data");
		}
		
		pwd = getIntent().getExtras().getCharArray("password");
		
		select.setOnClickListener(listener);
	}
	
	/**
	 * The listener class is an OnClickListener that changes the activity and passes on the mode, data, and chosen filename back to the
	 * NighthawkActivity class.
	 */
	OnClickListener listener = new OnClickListener()
	{
		/**
		 * Called when the select button is pressed.
		 */
		public void onClick(View v)
		{
			Intent i = new Intent(FilenameActivity.this, NighthawkActivity.class);
			i.putExtra("mode", mode);
			i.putExtra("data", data);
			i.putExtra("password", pwd);
			i.putExtra("filename", ((EditText) findViewById(R.id.basename)).getText().toString());
			startActivity(i);
		}
	};
	
	private int mode;
	private String data;
	private char[] pwd;
}
